import numpy as np
from matplotlib import pyplot as plt
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.offline as of  	# 这个为离线模式的导入方法np.delete(a, 1, 0)
a=np.load("../"+"YIG"+str(0)+"SIM.npy")
# ===================
# for i in range(1,100):
#     b=np.load("../"+"YIG"+str(i)+"SIM.npy")
#     a=np.concatenate((a,np.delete(b, 0, 0)),0)
# np.save("ALLYIGSIM.npy",a)
# b=np.zeros([100001,4])
# for i in range(100001):
#     b[i]=a[10*i]
# np.save("ALLDIV.npy",b)
mine=np.load("ALLDIV.npy")
mumax=np.loadtxt("table.txt")

ymine   = abs(np.fft.fft(mine[:,(1,2,3)],axis=0))
ymumax_  = abs(np.fft.fft(mumax[:,(1,2,3)],axis=0))
xmine=np.linspace(0,1e3,len(mine[:,0]))
xmumax=np.linspace(0,1e2,len(mumax[:,0]))
mumax_=mumax[:,(1,2,3)]
mine_=mine[:,(1,2,3)]
xaxis=xmine#mine[:,0]

# xaxis=mine[:,0]
# ymine=mine[:,(1,2,3)]

yaxis=ymine[:,0]
yaxis1=ymine[:,1]
yaxis2=ymine[:,2]

xmumax=xmumax#mumax[:,0]

# xmumax=mumax[:,0]
# ymumax_=mumax_

ymumax=ymumax_[:,0]
ymumax1=ymumax_[:,1]
ymumax2=ymumax_[:,2]

Mx=go.Scatter(x=xaxis, y=yaxis,
                    mode='lines',
                    name='mx_Python',
                    xaxis="x",yaxis="y",
                    line=dict(color='#D62728', width=2),)
My=go.Scatter(x=xaxis, y=yaxis1,
                    mode='lines',
                    name='my_Python',
                    xaxis="x",yaxis="y",
                    line = dict(color='#2CA02C', width=1.5),
                    )
Mz=go.Scatter(x=xaxis, y=yaxis2,
                    mode='lines',
                    name='mz_Python',
                    xaxis="x",yaxis="y",
                    line = dict(color='#FF7F0E', width=1.5),
                    )


Mxx=go.Scatter(x=xmumax, y=ymumax,
                    mode='lines',
                    name='mx_Mumax',
                    xaxis="x",yaxis="y",
                    line=dict(color='#2CA02C', width=1.5,dash="dot"),
                    )
Myy=go.Scatter(x=xmumax, y=ymumax1,
                    mode='lines',
                    name='my_Mumax',
                    xaxis="x",yaxis="y",
                    line = dict(color='#2CA02C', width=1.5,dash="dot"),
                    )
Mzz=go.Scatter(x=xmumax, y=ymumax2,
                    mode='lines',
                    name='mz_Mumax',
                    xaxis="x",yaxis="y",
                    line = dict(color='#FF7F0E', width=1.5,dash="dot"),
                    )


# Nzz=go.Scatter(x=xaxis, y=yaxis3,
#                     mode='lines+markers',
#                     name='Nzz',
#                     xaxis="x",yaxis="y",
#                     line = dict(color='royalblue', width=3,dash="dot"),
#                     marker=dict(color='royalblue', size=9),)
s1=go.Scatter(x=[2.5,2.5], y=[0,6500],
                    line = dict(color='#FF7F0E', width=1.5,dash="dot"),
                    mode='lines',showlegend=False,
                    name='2.5')
s2=go.Scatter(x=[2.55,2.55], y=[0,6500],
                    line = dict(color='#FF7F0E', width=1.5,dash="dot"),
                    mode='lines',showlegend=False,
                    name='2.5')
s3=go.Scatter(x=[2.6,2.6], y=[0,6500],
                    line = dict(color='#FF7F0E', width=1.5,dash="dot"),
                    mode='lines',showlegend=False,
                    name='2.5')
s4=go.Scatter(x=[2.45,2.45], y=[0,6500],
                    line = dict(color='#FF7F0E', width=1.5,dash="dot"),
                    mode='lines',showlegend=False,
                    name='2.5')
data = [s1,s2,s3,s4,Mxx,Mx]#My,Mz, Mxx,Myy,Mzz]#, Mxx2,Myy2,Mzz2]
# #====================================================
layout = go.Layout(
xaxis=dict(
    domain=[0, 0.99],
    title="Frequency (GHz)",
    exponentformat="e",
    showexponent="all",
    # range = [2.35,2.7],
    range = [4.65,5.35],
),   
yaxis=dict(
    domain=[0, 0.99],
    title="Spectrum (a.u.)",
    type="log", 
    range=[np.log10(0.08), np.log10(700)]
),   
font=dict(
    size=15,
),
legend=dict(
yanchor="top",
y=0.99,
xanchor="right",
x=0.99,
),
# showlegend=False,
    )
fig = go.Figure(data=data, layout=layout)
fig.update_xaxes(tickfont_size=20)#,title_text="sphericity")
fig.update_yaxes(tickfont_size=20)#,title_text="coplanarity")
fig.add_annotation(
    xref="x domain",
    yref="y domain",
    # The arrow head will be 25% along the x axis, starting from the left
    x=0.15/0.35,
    # The arrow head will be 40% along the y axis, starting from the bottom
    y=0.8,
    text="f1",
    arrowhead=3,
    font=dict(size=20,),
)
fig.add_annotation(
    xref="x domain",
    yref="y domain",
    # The arrow head will be 25% along the x axis, starting from the left
    x=0.2/0.35,
    # The arrow head will be 40% along the y axis, starting from the bottom
    y=0.8,
    text="f2",
    arrowhead=3,font=dict(size=20,),
)
fig.add_annotation(
    xref="x domain",
    yref="y domain",
    # The arrow head will be 25% along the x axis, starting from the left
    x=0.25/0.35,
    # The arrow head will be 40% along the y axis, starting from the bottom
    y=0.8,
    text="2f2-f1",
    arrowhead=3,font=dict(size=20,),
)
fig.add_annotation(
    xref="x domain",
    yref="y domain",
    # The arrow head will be 25% along the x axis, starting from the left
    x=0.1/0.35,
    # The arrow head will be 40% along the y axis, starting from the bottom
    y=0.8,
    text="2f1-f2",
    arrowhead=3,font=dict(size=20,),
)
# text="Bx=0<br>By=6e-4*sin(2*pi*2.5e9*t)+6e-4*sin(2*pi*2.55e9*t)<br>Bz=0.06"
# fig.add_annotation(text=text,   #附加text
#               xref="paper", yref="paper",
#               x=0.99, y=0.5, 
#         font=dict(
#             family="Courier New, monospace",
#             size=20,
#             color="#ffffff"
#             ),
#         bordercolor="#c7c7c7",
#         borderwidth=5,
#         borderpad=10,
#         bgcolor="#ff7f0e",
#         opacity=0.8,
#               showarrow=False)
# fig.add_trace(go.Scatter(x=[2.5,2.5], y=[0,6500],
#                     line = dict(color='#FF7F0E', width=1.5,dash="dot"),
#                     mode='lines',showlegend=False,
#                     name='2.5'))
# fig.add_trace(go.Scatter(x=[2.55,2.55], y=[0,6500],
#                     line = dict(color='#FF7F0E', width=1.5,dash="dot"),
#                     mode='lines',showlegend=False,
#                     name='2.5'))
# fig.add_trace(go.Scatter(x=[2.6,2.6], y=[0,6500],
#                     line = dict(color='#FF7F0E', width=1.5,dash="dot"),
#                     mode='lines',showlegend=False,
#                     name='2.5'))
# fig.add_trace(go.Scatter(x=[2.45,2.45], y=[0,6500],
#                     line = dict(color='#FF7F0E', width=1.5,dash="dot"),
#                     mode='lines',showlegend=False,
#                     name='2.5'))
#======================================================================
# fig.add_trace(go.Scatter(x=["1","2"], y=[a[2],b[2]],
#                     mode='lines+markers',
#                     name='Nzz'))
# fig.show()

# fig.write_image('spx.svg')
# of.plot(fig, filename="GHZ"+".html",image='svg')
fig.show()
